﻿
/// <reference path="base/framwork.js" />
/// <reference path="widget/iscroll.js" />
/// <reference path="base/jquery.js" />
/// <reference path="base/transit.js" />

$(document).ready(function () {
    var loadBox = $('aside.loadBox');
    var articleBox = $('article');
    icom.orient(init);

    function init() {
        //loadBox.show();
        //iuser.init(userGetted);
        load_handler();
    }

    function userGetted(data) {
        console.log('用户头像：' + data.headimage);
        console.log('用户昵称：' + data.nickname);
        load_handler();
    }

    function load_handler() {
        var loader = new PxLoader();
        loader.addImage('images/obg.jpg');
        //实际加载进度
        loader.addProgressListener(function (e) {
            var per = Math.round(e.completedCount / e.totalCount * 50);
            //loadPer.html(per + '%');
        });
        loader.addCompletionListener(function () {
            init_handler();
            loader = null;
        });
        loader.start();
    }


    function init_handler() {
        console.log('init handler');
        monitor_handler();
        $("footer").load("/module/foot.html");

        $.get('/webajax/BaseHandler.ashx', { method: 'GetYear' }, function (data) { $('.year').html(data) });

        $.get('/webajax/BaseHandler.ashx', { method: 'GetRally' }, function (data) {
            var now = new Date();
            for (var i = 0; i < data.length; i++) {
                var start = new Date(parseInt(data[i].StartTime.slice(6, 19)));
                var end = new Date(parseInt(data[i].EndTime.slice(6, 19)));

                var item = '<div class="item ' + (start > now ? 'can' : 'no') + '">\
                                <div class="nt"><div class="name">' + data[i].Name + '</div><div class="time">' + start.Format('M/d') + '-' + end.Format('M/d') + '</div></div>\
                                <a class="btn" val=' + data[i].ID + '></a>\
                            </div>';

                $('#list').append(item);
            }
            new IScroll('.list', { scrollbars: true, click: true });

            $('.item.can').find('.btn').on('click', function () {
                console.log(1);
                location.href = "reg_info.html?id=" + $(this).attr('val');
            })
        }, 'json');
    }

    //----------------------------------------页面监测代码----------------------------------------
    function monitor_handler() {
        //imonitor.add({obj:$('a.btnTest'),action:'touchstart',category:'首页',label:'测试按钮'});
    }

});

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}